package Solution101_200;

import java.util.ArrayList;
import java.util.List;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/18 17:08
 */
public class Solution119yanghuisanjiao2 {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> result0 = new ArrayList<>();
        List<Integer> result1 = new ArrayList<>();
        for (int i = 0; i <= rowIndex; i++) {
            if (i % 2 == 0) {
                getLevel(result1, result0, i);
            } else {
                getLevel(result0, result1, i);
            }
        }
        if (rowIndex % 2 == 0) {
            return result0;
        } else {
            return result1;
        }
    }

    private void getLevel(List<Integer> pre, List<Integer> curr, int index) {
        curr.clear();
        for (int j = 0; j <= index; j++) {
            if (j == 0 || j == index) {
                curr.add(1);
            } else {
                curr.add(pre.get(j - 1) + pre.get(j));
            }
        }
    }
}
